package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.LoanIndexModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.MineLoanContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Observer;

/**
 * Created by Jiangzx on 2017/9/6 17:27.
 */

public class MineLoanPresenter extends BasePresenter implements MineLoanContract.Presenter {
    public static final int POSITION_NONE=-1;
    public static final int POSITION_GRAB_ORDER=0;//实时抢单
    public static final int POSITION_EXCLUSIVE_ORDER =1;//专属订单
    public static final int POSITION_MINE_ORDER=2;//我的订单

    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil jsonUtil;

    private MineLoanContract.View view;

    @Inject
    public MineLoanPresenter(MineLoanContract.View view){
        this.view=view;
    }

    @Override
    public void getLoanIndex(final int clickedPosition, String saleID) {
        view.showLoadingDialog(mContext.getString(R.string.loading));
        jsonUtil.put("SalesID", saleID);

        ApiServiceHelper.
                appointThreadNormal(apiService.getLoanIndex(jsonUtil.getRsaParams())).
                subscribe(new Observer<LoanIndexModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(LoanIndexModel loanIndexModel) {
                        view.onLoanIndexSuccess(clickedPosition,loanIndexModel.getData());
                    }
                });
    }
}
